﻿using MC;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Station.Inspect.Forms
{
    public partial class FormConfig : Form
    {
        public FormConfig()
        {
            InitializeComponent();
        }

        private void FormConfig_Load(object sender, EventArgs e)
        {
            FormClosed += FormConfig_FormClosed;
            tbPixel2mm.Text = StaConfig.Instance.Pixel2mm.ToString();
            tbPixel2mmB.Text = StaConfig.Instance.Pixel2mmB.ToString();
            tbExposureTime.Text = StaConfig.Instance.ExposureTime.ToString();
            tbCellNum.Text = StaConfig.Instance.CellNum.ToString();
            cbEnableAdjust.Checked = StaConfig.Instance.EnableAdjust;
            tbTopZ1.Text = StaConfig.Instance.OrgTopZ1.ToString();
            tbBottomZ1.Text = StaConfig.Instance.OrgBottomZ1.ToString();
            tbTopZ2.Text = StaConfig.Instance.OrgTopZ2.ToString();
            tbBottomZ2.Text = StaConfig.Instance.OrgBottomZ2.ToString();
            //--光源控制器
            tbCOM.Text = StaConfig.Instance.lightCOM;
            tbTongdao.Text = StaConfig.Instance.lightChannel.ToString();
            tbTopLiang1.Text = StaConfig.Instance.brightnessTop1.ToString();
            tbBottomLiang1.Text = StaConfig.Instance.brightnessBottom1.ToString();
            tbTopLiang2.Text = StaConfig.Instance.brightnessTop2.ToString();
            tbBottomLiang2.Text = StaConfig.Instance.brightnessBottom2.ToString();
            //搬运1 2-原点
            tbPosA1.Text = StaConfig.Instance.PosA1.ToString();
            tbPosB1.Text = StaConfig.Instance.PosB1.ToString();
            tbPosA2.Text = StaConfig.Instance.PosA2.ToString();
            tbPosB2.Text = StaConfig.Instance.PosB2.ToString();
            //x y
            numCodeX1.Value = Convert.ToDecimal(StaConfig.Instance.codex1);
            numCodeY1.Value = Convert.ToDecimal(StaConfig.Instance.codey1);
            numCodeR1.Value = Convert.ToDecimal(StaConfig.Instance.coder1);

            numCodeX2.Value =Convert.ToDecimal( StaConfig.Instance.codex2);
            numCodeY2.Value = Convert.ToDecimal(StaConfig.Instance.codey2);
            numCodeR2.Value = Convert.ToDecimal(StaConfig.Instance.coder2);
            //增益
            numGain.Value= Convert.ToDecimal(StaConfig.Instance.Gain);
        }

        private void FormConfig_FormClosed(object sender, FormClosedEventArgs e)
        {
            FormDics.RemoveForm(this);
        }
        private void btnGetTopZ1_Click(object sender, EventArgs e)
        {
            tbTopZ1.Text = StaInspect.Instance.Rbt.GetCurPos().z.ToString();
        }

        private void btnGetBottomZ1_Click(object sender, EventArgs e)
        {
            tbBottomZ1.Text = StaInspect.Instance.Rbt.GetCurPos().z.ToString();
        }

        private void btnGetTopZ2_Click(object sender, EventArgs e)
        {
            tbTopZ2.Text = StaInspect.Instance.Rbt.GetCurPos().z.ToString();
        }

        private void btnGetBottomZ2_Click(object sender, EventArgs e)
        {
            tbBottomZ2.Text = StaInspect.Instance.Rbt.GetCurPos().z.ToString();
        }
        private void btnTopLiang1_Click(object sender, EventArgs e)
        {
            tbTopLiang1.Text = StaInspect.Instance.prjLight.ToString();
        }

        private void btnBottomLiang1_Click(object sender, EventArgs e)
        {
            tbBottomLiang1.Text = StaInspect.Instance.prjLight.ToString();
        }

        private void btnTopLiang2_Click(object sender, EventArgs e)
        {
            tbTopLiang2.Text = StaInspect.Instance.prjLight.ToString();
        }

        private void btnBottomLiang2_Click(object sender, EventArgs e)
        {
            tbBottomLiang2.Text = StaInspect.Instance.prjLight.ToString();
        }

        private void btnPosA2_Click(object sender, EventArgs e)
        {
            TargetPos tt = StaInspect.Instance.GetCurPos();
            tbPosA2.Text = tt.ToString();
            StaConfig.Instance.PosA2 = tt;
        }
        private void btnPosB2_Click(object sender, EventArgs e)
        {
            TargetPos tt = StaInspect.Instance.GetCurPos();
            tbPosB2.Text = tt.ToString();
            StaConfig.Instance.PosB2 = tt;
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            StaConfig.Instance.Pixel2mm = double.Parse(tbPixel2mm.Text);
            StaConfig.Instance.Pixel2mmB = double.Parse(tbPixel2mmB.Text);
            StaConfig.Instance.ExposureTime = int.Parse(tbExposureTime.Text);
            StaConfig.Instance.CellNum = int.Parse(tbCellNum.Text);
            StaConfig.Instance.EnableAdjust = cbEnableAdjust.Checked;
            StaConfig.Instance.OrgTopZ1 = double.Parse(tbTopZ1.Text);
            StaConfig.Instance.OrgBottomZ1 = double.Parse(tbBottomZ1.Text);
            StaConfig.Instance.OrgTopZ2 = double.Parse(tbTopZ2.Text);
            StaConfig.Instance.OrgBottomZ2 = double.Parse(tbBottomZ2.Text);
            //--光源控制器
            StaConfig.Instance.lightCOM = tbCOM.Text.Trim();
            StaConfig.Instance.lightChannel = int.Parse(tbTongdao.Text);
            StaConfig.Instance.brightnessTop1 = int.Parse(tbTopLiang1.Text);
            StaConfig.Instance.brightnessBottom1 = int.Parse(tbBottomLiang1.Text);
            StaConfig.Instance.brightnessTop2 = int.Parse(tbTopLiang2.Text);
            StaConfig.Instance.brightnessBottom2 = int.Parse(tbBottomLiang2.Text);
            // x y
            StaConfig.Instance.codex1 = Convert.ToDouble(numCodeX1.Value);
            StaConfig.Instance.codey1 = Convert.ToDouble(numCodeY1.Value);
            StaConfig.Instance.coder1 = Convert.ToDouble(numCodeR1.Value);
            //
            StaConfig.Instance.codex2 = Convert.ToDouble(numCodeX2.Value);
            StaConfig.Instance.codey2 = Convert.ToDouble(numCodeY2.Value);
            StaConfig.Instance.coder2 = Convert.ToDouble(numCodeR2.Value);
            //增益
            StaConfig.Instance.Gain = Convert.ToDouble(numGain.Value);
            //StaConfig.Instance.Save();
            StaConfig.Instance.Save(StaInspect.Instance.loadPath);

        }

        private void btnPosA1_Click(object sender, EventArgs e)
        {
            TargetPos tt = StaInspect.Instance.GetCurPos();
            tbPosA1.Text = tt.ToString();
            StaConfig.Instance.PosA1 = tt;
        }

        private void btnPosB1_Click(object sender, EventArgs e)
        {
            TargetPos tt = StaInspect.Instance.GetCurPos();
            tbPosB1.Text = tt.ToString();
            StaConfig.Instance.PosB1 = tt;
        }
    }
}
